using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using NBModular.Module.WeChat.Application.WeChatService;
using NBModular.Module.WeChat.Application.WeChatService.ViewModels;
using NBModular.Module.WeChat.Domain.WeChat.Models;

namespace NBModular.Module.WeChat.Web.Controllers
{
    [Description("微信配置管理")]
    public class WeChatController : ModuleController
    {
        private readonly IWeChatService _service;

        public WeChatController(IWeChatService service)
        {
            _service = service;
        }

        [HttpGet]
        [Description("查询")]
        public Task<IResultModel> Query([FromQuery]WeChatQueryModel model)
        {
            return _service.Query(model);
        }

        [HttpPost]
        [Description("添加")]
        public Task<IResultModel> Add(WeChatAddModel model)
        {
            return _service.Add(model);
        }

        [HttpDelete]
        [Description("删除")]
        public Task<IResultModel> Delete([BindRequired]Guid id)
        {
            return _service.Delete(id);
        }

        [HttpGet]
        [Description("编辑")]
        public Task<IResultModel> Edit([BindRequired]Guid id)
        {
            return _service.Edit(id);
        }

        [HttpPost]
        [Description("修改")]
        public Task<IResultModel> Update(WeChatUpdateModel model)
        {
            return _service.Update(model);
        }

        [HttpPost]
        [AllowAnonymous]
        [Description("获取GLOBAL_ACCESS_TOKEN")]
        public async Task<IResultModel> GetTokenAsync(string appid) 
        {
            return await _service.GetTokenAsync(appid);
        }
    }
}
